import socket

import handler

host = ''

port = 80

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

s.bind((host, port))

s.listen(10)


def run():
    while 1:
        clientsock, clientaddr = s.accept()
        print('client connected from', clientaddr)
        response = clientsock.makefile('rwb', 0)
        res = handler.deal_request(response)
        clientsock.send(res)
        clientsock.close()
